home *** CD-ROM | disk | FTP | other *** search
/ Web Star/List Star - Eve…he Ultimate Internet Site / StarNine Internet Pubisher (Web Star and List Star)(StarNine)(1995).iso / Extras / Scripting Solutions / DePlus OSAX 1.0 / DePlus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-22  |  2.3 KB  |  83 lines  |  [TEXT/R*ch]

  1. /********************************************
  2.  * Decode Plus OSAX - by Jon Wiederspan 11/22/94
  3.  * Based on DecodeURL by Chuck Shotton.
  4.  * This code, the OSAX, and all of its constituent parts are hereby
  5.  * placed in the public domain.
  6.  *
  7.  * This code converts "+" to spaces in text passed to it.
  8.  *
  9.  * This code was written using Think C. It should be build as a 68k
  10.  * code resource to avoid problems. The code resource type is 'osax'
  11.  * and its resource ID MUST match the event class and code.
  12.  * For this event the name is "AEVTaevtdPls", indicating that this is
  13.  * an AppleEvent, class aevt, code dPls.
  14.  *********************************************/
  15.  
  16. #include <AppleEvents.h> 
  17.  
  18. /*********************************************/
  19.  
  20. pascal OSErr main(    AppleEvent *theAEEvent, 
  21.                             AppleEvent *theReply, 
  22.                             long *theRefCon) 
  23.  
  24. {     
  25.     /* variables */
  26.     OSErr            theErr = noErr;     
  27.     DescType         typeCode;
  28.     Size             sizeOfParam,
  29.                     actualSize;
  30.     char *url;
  31.     int i;
  32.     unsigned char bite;
  33.     
  34.     theErr = AESizeOfParam(    theAEEvent,
  35.                                keyDirectObject,
  36.                                &typeCode,
  37.                                &sizeOfParam);
  38.   
  39.     if (theErr != noErr){            
  40.         return theErr;
  41.     }     
  42.     else{  
  43.         /*try converting lots of types of strings into something we can use*/
  44.         if ((typeCode == typeChar) || (typeCode == typeStyledText) || 
  45.             (typeCode == typeIntlText)) {        
  46.         
  47.             /*Make a place to store the parameter, then get it.*/
  48.             if (url = (char *) NewPtr (sizeOfParam+2)) {
  49.                 theErr = AEGetParamPtr(theAEEvent, keyDirectObject, typeChar, 
  50.                                          &typeCode, (Ptr) url, 
  51.                                         sizeOfParam+1, &actualSize);
  52.                                         
  53.                 if(theErr == noErr) {
  54.                     /* 'C' string has a null as last char */
  55.                     url [actualSize] = '\0';
  56.                     i=0;
  57.                     
  58.                     /*decode the %xx encodings*/
  59.                     while ( url[i] ) {
  60.                         while ( url[i] ) {
  61.                             /* This is the only line I changed from DecodeURL */
  62.                             if (url [i]=='+') {
  63.                                 url [i] = ' ';
  64.                             }
  65.                             i++;
  66.                         }
  67.                     }
  68.                 }
  69.                 /*return the result of any processing to the caller*/
  70.                 if (theReply->descriptorType != typeNull) 
  71.                     theErr = AEPutParamPtr(theReply, keyDirectObject, typeChar,
  72.                         url, actualSize );
  73.                 DisposPtr (url);
  74.             }
  75.             else return errAEEventNotHandled;
  76.         }
  77.         else // Wasn't a string so bail
  78.             return errAEEventNotHandled;
  79.     } 
  80.         
  81.     return theErr;
  82.  }
  83.